using System;

namespace Slaks.Readers
{
	public abstract class ArabSpecNormalization
	{
    /// <summary>
    /// Removes several characters in the beginning of the word
    /// from right to left (hex)
    /// 1.if found -> 0x644 0x627 0x648 , remove 0x648
    /// 2.if found -> 0x644 0x627 0x643 , remove 0x643
    /// 3.if found -> 0x644 0x627 0x628 , remove 0x628
    /// 4.if found -> 0x644 0x627 0x641 , remove 0x641
    /// 5.if found -> 0x644 0x644       , remove 0x644 0x644
    /// </summary>
    /// <param name="term"></param>
    /// <returns></returns>
    public static string Normalize(string term)
    {
      string newTerm = String.Empty;

      if (term.Length == 1) return term;
      if (term.Length >= 2)
      {
        if (term[0] == 0x644 && term[1] == 0x644) 
        {
          newTerm = term.Substring(2);
          return newTerm;
        }
      }
      if (term.Length >=3)
      {
        if (term[0] == 0x648 && term[1] == 0x627 && term[2] == 0x644) newTerm = term.Substring(1);
        else if (term[0] == 0x643 && term[1] == 0x627 && term[2] == 0x644) newTerm = term.Substring(1);
        else if (term[0] == 0x628 && term[1] == 0x627 && term[2] == 0x644) newTerm = term.Substring(1);
        else if (term[0] == 0x641 && term[1] == 0x627 && term[2] == 0x644) newTerm = term.Substring(1);
        if (newTerm != String.Empty) 
        {
          return newTerm;
        }
      }
      return term;
    }
	}
}
